<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>每次进入输入密码</title>
  <style>
    /* 基础样式重置 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Helvetica', 'Arial', sans-serif;
    }

    /* 自定义工具类 */
    .btn-hover {
      transition: all 0.2s ease;
    }

    .btn-hover:hover:not(:disabled) {
      transform: scale(1.05);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    /* 主体样式 */
    body {
      background-color: #F7F9FC;
      min-height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .app-container {
      width: 100%;
      max-width: 480px;
      min-height: 100vh;
      background: linear-gradient(to bottom, #165DFF 0%, #0F4CD8 100%);
      display: flex;
      flex-direction: column;
      padding: 40px 25px;
    }

    /* 标题区域 */
    .title-section {
      text-align: center;
      margin-bottom: 40px;
      padding-top: 40px;
    }

    .title {
      font-size: 26px;
      color: white;
      font-weight: 500;
      margin-bottom: 30px;
      text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    }

    /* 密码指示器 */
    .password-indicators {
      display: flex;
      justify-content: center;
      gap: 20px;
      margin-bottom: 40px;
    }

    .indicator {
      width: 16px;
      height: 16px;
      border: 2px solid rgba(255, 255, 255, 0.7);
      border-radius: 50%;
      opacity: 0.7;
      transition: all 0.3s ease;
    }

    .indicator.active {
      background-color: white;
      opacity: 1;
      transform: scale(1.2);
      box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    }

    /* OK按钮 */
    .ok-button {
      width: 160px;
      height: 56px;
      background-color: rgba(255, 255, 255, 0.2);
      border: none;
      border-radius: 30px;
      color: white;
      font-size: 18px;
      font-weight: bold;
      margin: 0 auto 40px;
      cursor: not-allowed;
      transition: all 0.3s ease;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .ok-button.active {
      background-color: white;
      color: #165DFF;
      cursor: pointer;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }

    .ok-button.active:hover {
      background-color: #f0f0f0;
    }

    /* 数字键盘 */
    .keypad {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 20px;
      margin-top: auto;
    }

    .key {
      width: 100%;
      height: 80px;
      max-width: 95px;
      margin: 0 auto;
      border-radius: 50%;
      background-color: white;
      border: none;
      font-size: 26px;
      color: #165DFF;
      font-weight: bold;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      box-shadow: 0 5px 10px rgba(0, 0, 0, 0.12);
      position: relative;
      overflow: hidden;
      user-select: none;
    }

    .key::after {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      width: 120%;
      height: 120%;
      background-color: rgba(255, 255, 255, 0.3);
      transform: translate(-50%, -50%) scale(0);
      border-radius: 50%;
      transition: transform 0.3s ease;
    }

    .key:active::after {
      transform: translate(-50%, -50%) scale(1);
    }

    /* 删除按钮优化 */
    .delete-key {
      position: relative;
      background-color: rgba(255, 255, 255, 0.9);
    }

    .delete-icon {
      width: 30px;
      height: 30px;
      position: relative;
    }

    .delete-icon::before {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(45deg);
      width: 18px;
      height: 3px;
      background-color: #165DFF;
      border-radius: 2px;
    }

    .delete-icon::after {
      content: '';
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(-45deg);
      width: 18px;
      height: 3px;
      background-color: #165DFF;
      border-radius: 2px;
    }

    /* 底部空间 */
    .bottom-space {
      height: 30px;
    }

    /* 响应式调整 */
    @media (max-width: 375px) {
      .app-container {
        padding: 30px 20px;
      }

      .key {
        height: 70px;
        max-width: 80px;
        font-size: 22px;
      }

      .password-indicators {
        gap: 15px;
        margin-bottom: 30px;
      }

      .ok-button {
        width: 140px;
        height: 50px;
        font-size: 17px;
      }

      .delete-icon {
        width: 26px;
        height: 26px;
      }
    }

    @media (max-width: 320px) {
      .keypad {
        gap: 15px;
      }

      .key {
        height: 65px;
        max-width: 70px;
      }

      .title {
        font-size: 24px;
      }

      .ok-button {
        width: 130px;
        height: 45px;
      }

      .delete-icon {
        width: 24px;
        height: 24px;
      }
    }
  </style>
</head>

<body>
  <div class="app-container">
    <!-- 标题区域 -->
    <div class="title-section">
      <h2 class="title">请输入密码</h2>

      <!-- 密码指示器 -->
      <div class="password-indicators">
        <div class="indicator"></div>
        <div class="indicator"></div>
        <div class="indicator"></div>
        <div class="indicator"></div>
      </div>

      <!-- OK按钮 -->
      <button class="ok-button" disabled>OK</button>
    </div>

    <!-- 数字键盘 -->
    <div class="keypad">
      <button class="key btn-hover" data-number="1">1</button>
      <button class="key btn-hover" data-number="2">2</button>
      <button class="key btn-hover" data-number="3">3</button>
      <button class="key btn-hover" data-number="4">4</button>
      <button class="key btn-hover" data-number="5">5</button>
      <button class="key btn-hover" data-number="6">6</button>
      <button class="key btn-hover" data-number="7">7</button>
      <button class="key btn-hover" data-number="8">8</button>
      <button class="key btn-hover" data-number="9">9</button>
      <div class="key" style="visibility: hidden;"></div> <!-- 空键位 -->
      <button class="key btn-hover" data-number="0">0</button>
      <button class="key btn-hover delete-key" id="delete-key">
        <div class="delete-icon"></div>
      </button>
    </div>

    <div class="bottom-space"></div>
  </div>

  <script>
    document.addEventListener('DOMContentLoaded', () => {
      // 获取DOM元素
      const keyButtons = document.querySelectorAll('.key[data-number]');
      const deleteButton = document.getElementById('delete-key');
      const okButton = document.querySelector('.ok-button');
      const indicators = document.querySelectorAll('.indicator');

      let password = [];
      const maxPasswordLength = 4;

      // 数字键点击事件
      keyButtons.forEach(button => {
        button.addEventListener('click', () => {
          if (password.length < maxPasswordLength) {
            // 添加密码数字
            password.push(button.dataset.number);

            // 更新指示器
            updateIndicators();

            // 检查是否可以激活OK按钮
            if (password.length === maxPasswordLength) {
              okButton.classList.add('active');
              okButton.disabled = false;

              // 添加按键成功的震动反馈（如果设备支持）
              if ("vibrate" in navigator) {
                navigator.vibrate(20);
              }
            }
          }
        });
      });

      // 删除键点击事件 - 修复后的绑定
      deleteButton.addEventListener('click', () => {
        if (password.length > 0) {
          // 删除最后一个密码数字
          password.pop();

          // 更新指示器
          updateIndicators();

          // 如果密码不足4位，禁用OK按钮
          if (password.length < maxPasswordLength) {
            okButton.classList.remove('active');
            okButton.disabled = true;
          }

          // 添加删除反馈（如果设备支持）
          if ("vibrate" in navigator) {
            navigator.vibrate(15);
          }
        }
      });

      // OK按钮点击事件
      okButton.addEventListener('click', () => {
        if (password.length === maxPasswordLength && !okButton.disabled) {
          // 添加成功提交的震动反馈（如果设备支持）
          if ("vibrate" in navigator) {
            navigator.vibrate([20, 10, 20]);
          }

          // 跳转到主页
          window.location.href = '主页.html';
        }
      });

      // 更新密码指示器
      function updateIndicators() {
        indicators.forEach((indicator, index) => {
          if (index < password.length) {
            indicator.classList.add('active');
          } else {
            indicator.classList.remove('active');
          }
        });
      }

      // 添加键盘支持
      document.addEventListener('keydown', (e) => {
        if (e.key >= '0' && e.key <= '9') {
          const keyButton = [...keyButtons].find(btn => btn.dataset.number === e.key);
          if (keyButton) {
            keyButton.click();

            // 添加点击效果
            keyButton.classList.add('btn-active');
            setTimeout(() => keyButton.classList.remove('btn-active'), 150);
          }
        } else if (e.key === 'Backspace' || e.key === 'Delete') {
          deleteButton.click();

          // 添加点击效果
          deleteButton.classList.add('btn-active');
          setTimeout(() => deleteButton.classList.remove('btn-active'), 150);
        } else if (e.key === 'Enter' && okButton.classList.contains('active')) {
          okButton.click();

          // 添加点击效果
          okButton.classList.add('btn-active');
          setTimeout(() => okButton.classList.remove('btn-active'), 150);
        }
      });
    });
  </script>
</body>

</html>